

using System.Numerics;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_Normalize_RT : RT_Node
    {
        public RT_SingleValuePort InputVector_RT;

        public RT_SingleValuePort Normalized_RT;

        public Node_Normalize_RT(Node_Normalize sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            InputVector_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.InputVector, this);

            Normalized_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Normalized, this);
            Normalized_RT.OnGetValue = GetNormalized;
        }

        public AValue GetNormalized(DAG_Executor executor)
        {
            var inVec = InputVector_RT.GetValue(executor);
            var vecType = inVec.ValueType;
            if (vecType == AValue.EValueType.Vector2)
            {
                Vector2 inVec2 = inVec.ToVector2().Item2;
                Vector2 normalized = Vector2.Normalize(inVec2);
                Normalized_RT.SourceValue.SetVector2(normalized);
            }
            else if (vecType == AValue.EValueType.Vector3)
            {
                Vector3 inVec3 = inVec.ToVector3().Item2;
                Vector3 normalized = Vector3.Normalize(inVec3);
                Normalized_RT.SourceValue.SetVector3(normalized);
            }
            return Normalized_RT.SourceValue;
        }
    }
}